package com.cc.spring.utils;

import com.auth0.jwt.interfaces.DecodedJWT;
import com.cc.spring.exception.BusinessException;
import com.cc.spring.exception.BusinessExceptionCode;

import javax.servlet.http.HttpServletRequest;

public class AuthUtil {
    public static boolean authIsAble(HttpServletRequest request){
        String token = request.getHeader("token");
        DecodedJWT decodedJWT = JWTUtil.verifyToken(token);
        String permission1 = decodedJWT.getClaim("permission").asString();
//        有权限才能删除
        //            那就抛出一个异常
        //            throw new BusinessException(BusinessExceptionCode.PERMISSION_NOT_ABLE);
//        是否有权限，1代表没有权限
        return permission1.equals("1");
    }
}
